home *** CD-ROM | disk | FTP | other *** search
- /* File.c */
-
- #include "AESimple.h"
-
- Boolean select_file (FSSpec *theFile)
- /* Get an FSSpec for the selected file. I'm feeling lazy, so I'll use the */
- /* new StandardGetFile call, which returns an FSSpec. You can do the same */
- /* thing under System 6 by calling SFGetFile and then using HGetCatInfo */
- /* to convert the working directory ID to a volume & dir ID. */
- {
- SFTypeList typeList = {'PICT', ' ', ' ', ' '};
- StandardFileReply reply;
-
- StandardGetFile(NIL, 1, typeList, &reply);
- if (reply.sfGood)
- *theFile = reply.sfFile;
-
- return reply.sfGood;
- } /* select_file */
-
-
- OSErr open_selected_file (FSSpec *theFile, WindowPtr wp)
- /* This routine opens the specified file and reads it into the specified window */
- /* */
- /* If you're working with System 7, your file read routine should take an FSSpec*/
- /* as you won't be given a working directory. */
- /* */
- /* If you need to work with both System 6 and System 7, you should use HOpen in */
- /* place of FSpopenDF (and _still_ create an FSSpec, which you feed to HOpen as */
- /* 3 seperate parameters. */
- /* */
- /* Note that we're reading in a PICT without spooling it in -- see TN #154 for */
- /* the details on how to read in large pictures. */
- {
- wiHand info;
- OSErr err = noErr;
- short refNum = 0;
- long logEOF = 0;
- Handle buffer;
-
- if (wp != NIL) {
- info = (wiHand)GetWRefCon(wp);
- err = FSpOpenDF(theFile, fsRdPerm, &refNum); /* New System 7 call. */
- if (err == noErr) {
- err = GetEOF(refNum, &logEOF);
- if (logEOF > 512) {
- buffer = NewHandle(logEOF - 512);
- MoveHHi(buffer);
- HLock(buffer);
- err = SetFPos(refNum, fsFromStart, 512); /* Skip over the header */
- err = FSRead(refNum, &logEOF, *buffer);
- HUnlock(buffer);
- if ((*info)->thePicture == NIL)
- KillPicture((*info)->thePicture);
- (*info)->thePicture = (PicHandle)buffer;
- }
- err = FSClose(refNum);
- refNum = 0;
- (*info)->picBounds = (*(*info)->thePicture)->picFrame;
- SetWTitle(wp, theFile->name);
- SetScrollMaxima(wp, info, TRUE);
- }
- }
-
- return err;
- } /* open_selected_file */